function jcb_plot_winspec_ascii(pathname,recursive)

specpattern='*.spe';
xsize=1024;
if nargin>=1
    if nargin < 2
        recursive=false;
    end
    
    if recursive
        subdirs = dir(pathname);
        subdirs = subdirs([subdirs.isdir]);
        subdirs={subdirs.name}';
        
        for ii=1:length(subdirs)
            if ~strcmpi(subdirs{ii},'.') && ~strcmpi(subdirs{ii},'..')
                 jcb_plot_winspec_ascii(fullfile(pathname,subdirs{ii}),true);
            end
        end
    end
    
    filelist = dir(fullfile(pathname,specpattern));
    filelist = {filelist.name}';
    
end
if nargin<1
    [filelist,pathname] = jcb_pick_files(specpattern,'Select winspec files to plot',true,pwd);
end

for ii=1:length(filelist)
    specfile  = fullfile(pathname,filelist{ii});
    asciifile = regexprep(specfile,'\.[sS][pP][eE]','.txt');
    picfile   = regexprep(specfile,'\.[sS][pP][eE]','_spectrum.png');
    
    if strcmpi(specfile,asciifile) || strcmpi(specfile,picfile)
        warning('jcb:filenameerror','couldn''t deduce ascii filename from spectrum filename "%s"',specfile);
        continue
    end
    
    if ~exist(asciifile,'file')
%         warning('jcb:fileexisterror','ASCII file\n"%s"\nfor spectrum\n"%s"\ndoes not exist yet!',asciifile,specfile);
        disp(['ASCII file "' asciifile '" does not exist']);
        continue
    end
    
    data=load(asciifile);
    
    if size(data,2)~=2
        warning('jcb:jcb_file_format','Format error: file "%s" \nhas %d columns!',asciifile);
        continue
    end
    
    if exist(picfile,'file')
%         warning('jcb:jcb_file_exist','The file "%s" already exists!\nIt will not be overwritten.',picfile);
        disp(['Image "' picfile '" already exists']);
    else
        clf;
        plot(data(:,1),data(:,2));
        xlim(min(data(:,1))+[0,1]*range(data(:,1)));
        ylim(min(data(:,2))+[-0.05,1.05]*range(data(:,2)));
        xlabel('\lambda / nm');
        ylabel('counts');
        title(fullfile(pathname,strrep(filelist{ii},'.txt','.spe')),'interpreter','none');
        set(gcf,'PaperPositionMode','auto','units','pixels','position',[50 50 xsize-1 xsize*3/4]);
        set(gca,'units','normalized');
        set(gca,'position',[0.07 0.075 0.9 0.85]);
        print('-dpng','-r0',picfile);
        disp(specfile);
    end
end